
import 'package:account/bean/user.dart';
import 'package:shared_preferences/shared_preferences.dart';

class Cache {
  static const String _PWD = "pwd";
  static const String _PWD_TIP = "pwdTip";
  static SharedPreferences? _sp;

  static User? user;

  static init() async {
    _sp = await SharedPreferences.getInstance();
  }

  ///设置密码相关内容
  static setUser(User user) async {
    Cache.user = user;
    await _sp!.setString(_PWD, user.pwd!);
    await _sp!.setString(_PWD_TIP, user.pwdTip!);
  }

  ///获取密码相关内容
  static Future<User> getUser() async {
    return User(_sp!.getString(_PWD), _sp!.getString(_PWD_TIP));
  }
}
